package com.loongtech.bi.action.monitor;

import com.loongtech.bi.action.authManagement.ResultData;
import com.loongtech.bi.entity.POJO.Page;
import com.loongtech.bi.entity.system.EntityVipFightCoefficient;
import com.loongtech.bi.manager.system.SyncInfoLogManager;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.manager.system.VipFightCoefficientManager;
import com.loongtech.bi.support.Session;
import com.loongtech.core.util.RetCode;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author: yuri
 * Description: VIP战斗力配置
 * Date: 18:36 2017/5/15
 */
@RestController
@Scope("prototype")
@RequestMapping("/vip")
public class VipFightCoefficientAction {
    @Resource
    private VipFightCoefficientManager vipFightCoefficientManager;
    @Resource
    private Session session;
    @Resource
    private SysLogManager sysLogManager;
    @Resource
    private SyncInfoLogManager syncInfoLogManager;


    /**
     * 查询
     */
    @RequestMapping(value = "list.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultData<?> searchByCriteria(@RequestParam Integer curPage, @RequestParam Integer pageSize, EntityVipFightCoefficient e) {
        Page<List<EntityVipFightCoefficient>> list;
        try {
            list = vipFightCoefficientManager.queryByCriteria(curPage, pageSize, e);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultData.otherException();
        }
        return new ResultData<>(RetCode.eSuccess.getErrorcode(), list);
    }

    /**
     * 增加
     */
    @RequestMapping(value = "add.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultData<String> add(EntityVipFightCoefficient entity) {
        if (entity.getGameId() == null) {
            return new ResultData<>(RetCode.eEmptyId.getErrorcode(), RetCode.eEmptyId.getErrorMsg());
        }
        try {
            vipFightCoefficientManager.persist(entity);
            sysLogManager.addLog(session.getUserName(), "增加vip配置成功(" + entity.getGameName() + ")");
//            syncInfoLogManager.add(entity.getGameId(), EnumTableName.vipCoefficient.getTableName());
            return ResultData.success();
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultData.otherException();
        }
    }

    /**
     * 删除
     */
    @RequestMapping(value = "delete.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultData<String> delete(@RequestParam(value = "id") Integer id) {
        try {
            EntityVipFightCoefficient cur = vipFightCoefficientManager.get(id);
            if (cur != null) {
                vipFightCoefficientManager.removeById(id);
                sysLogManager.addLog(session.getUserName(), "vip配置删除成功");
//                syncInfoLogManager.add(cur.getGameId(), EnumTableName.vipCoefficient.getTableName());
                return ResultData.success();
            } else {
                return new ResultData<>(RetCode.eNotExistGourp.getErrorcode(), RetCode.eNotExistGourp.getErrorMsg());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultData.otherException();
        }
    }

    /**
     * 修改
     */
    @RequestMapping(value = "modify.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultData<String> modify(EntityVipFightCoefficient entity) {
        if (entity.getGameId() == null) {
            return new ResultData<>(RetCode.eEmptyId.getErrorcode(), RetCode.eEmptyId.getErrorMsg());
        }
        try {
            EntityVipFightCoefficient cur = vipFightCoefficientManager.get(entity.getId());
            if (cur != null) {
                entity.setCreateTime(cur.getCreateTime());
                vipFightCoefficientManager.merge(entity);
                sysLogManager.addLog(session.getUserName(), "vip配置修改成功");
//                syncInfoLogManager.add(entity.getGameId(), EnumTableName.vipCoefficient.getTableName());
                return ResultData.success();
            } else {
                return new ResultData<>(RetCode.eNotExistGourp.getErrorcode(), RetCode.eNotExistGourp.getErrorMsg());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultData.otherException();
        }
    }
}
